﻿/*
=======================================================
    RegulatorPermission【功能权限】
=======================================================
*/

namespace Services
{
    public interface IRegulatorPermissionRepository : IRepository<RegulatorPermission>
    {
    }


    public class RegulatorPermissionRepository : BaseRepository<RegulatorPermission>, IRegulatorPermissionRepository
    {
        public RegulatorPermissionRepository(ISqlSugarClient dB, ICurrentUser currentUser, IQuery<RegulatorPermission> query)
            : base(dB, currentUser, query)
        {
        }

        #region BatchInsert
        public override int BatchInsert(List<RegulatorPermission> entities)
        {
            int regluatorID = entities.First().RegulatorID;

            _DB.Deleteable<RegulatorPermission>().Where(x => x.RegulatorID == regluatorID).ExecuteCommand();

            var newEntities = entities.Select(x => new RegulatorPermission
            {
                RegulatorID = regluatorID,
                PermissionID = x.PermissionID,
            }).ToList();

            return _DB.Insertable(newEntities).ExecuteCommand();
        } 
        #endregion
    }
}
